package com.dhkj.web.idf;

import android.content.Context;

import com.alibaba.fastjson.JSONObject;
import com.dhkj.web.idf.model.DeviceLoginWraper;
import com.dhkj.web.idf.model.LoginWraper;
import com.dhkj.web.idf.model.MerchantWraper;
import com.dhkj.web.utils.MyObserverNo;
import com.dhkj.web.utils.RxHelper;

import okhttp3.MediaType;
import okhttp3.RequestBody;

public class IdfTagRequestUtils {

    public static void listMerchant(Context context, MyObserverNo<MerchantWraper> observer) {
        RetrofitIdfTagUtils.getApiUrl().listMerchant()
                .compose(RxHelper.observableIO2Main(context))
                .subscribe(observer);
    }

    public static void deviceLogin(Context context, String registrationNumber, MyObserverNo<DeviceLoginWraper> observer) {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("registrationNumber", registrationNumber);
        RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), jsonObject.toJSONString());
        RetrofitIdfTagUtils.getApiUrl().deviceLogin(requestBody).compose(RxHelper.observableIO2Main(context)).subscribe(observer);
    }

    public static void login(Context context, String username, String password, long devicePK, MyObserverNo<LoginWraper> observer) {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("userId", username);
        jsonObject.put("password", password);
        jsonObject.put("devicePK", devicePK);
        RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), jsonObject.toJSONString());
        RetrofitIdfTagUtils.getApiUrl().login(requestBody).compose(RxHelper.observableIO2Main(context)).subscribe(observer);
    }


}
